//
//  LspNbHomeViewController.swift
//  LspSwiftFinayTest
//
//  Created by lsp's mac pro on 2018/3/27.
//  Copyright © 2018年 lsp's mac pro. All rights reserved.
//

import UIKit

private let cellId="cellId"
class LspNbHomeViewController: LspNbBaseViewController {

    private lazy var listViewModel=LspNbStatusListViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpNavTitle()
        
    }

    @objc  private func clickFriends()  {
    let  vc = LspNbDemoTestViewController()
    navigationController?.pushViewController(vc, animated: true);
    }
    
    override func loadData() {
        
        listViewModel.loadStatus(pullup: self.isPull) { (isSuccess,haveMorePullUp) in
            self.refrshControl?.endRefreshing()
            self.isPull=false
            if haveMorePullUp{
             self.tableView?.reloadData()
            }
            
        }

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
extension LspNbHomeViewController{
    //具体的数据源方法重写的时候不需要super
  override  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listViewModel.statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as!LspNbNormalCell
        
        cell.contentLabel?.text=listViewModel.statusList[indexPath.row].text;
        
        return cell
    }
    
 
}

extension LspNbHomeViewController{
    //重写父类的方法
    override func setupTableView() {
        super.setupTableView()
        //系统的 最平常的导航条的左边的按钮
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(clickFriends))
        
        //自定义导航条的按钮（复杂方法）
//        let btn : UIButton=UIButton.cz_textButton("好友", fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
//        btn.addTarget(self, action: #selector(clickFriends), for: .touchUpInside)
//        navigationItem.leftBarButtonItem=UIBarButtonItem(customView: btn)
        
        //自定义导航条的按钮（写了UIBarButtonItem的扩展之后）
        navItem.leftBarButtonItem=UIBarButtonItem(title: "好友", target: self, action: #selector(clickFriends))
        //注册原型cell
//        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
       
        tableView?.register( UINib(nibName: "LspNbNormalCell", bundle: nil), forCellReuseIdentifier: cellId)
        tableView?.rowHeight=UITableViewAutomaticDimension
        tableView?.estimatedRowHeight=300
        tableView?.separatorStyle = .none
        
        
        
    }
    
    
  private func setUpNavTitle() {
    let title = LspNbNetWorkManage.shared.userModel.screen_name
    let button = LspNbTextButton(title: title)
    navItem.titleView=button
    button.addTarget(self, action: #selector(buttonClcik), for: .touchUpInside)
   
    }
    
    @objc func buttonClcik(btn:UIButton)  {
        //设置选中状态
        btn.isSelected = !btn.isSelected
    }
}

